import router from '@/router'
import { NOT_LOGIN } from './accessEnum'
import { accessRole } from './accessRole'
import { useUserStore } from '@/stores/user'

router.beforeEach((to, from, next) => {
  const needRole = (to.meta.access as string) || NOT_LOGIN
  const userRole = useUserStore().userLoginState?.userRole || NOT_LOGIN

  if (!accessRole(userRole, needRole)) {
    next('/nuAuth')
  }

  next()
})
